package com.example.whereismystuff.views;

import java.util.ArrayList;
import java.util.Calendar;

import com.example.whereismystuff.R;
import com.example.whereismystuff.classes.Item;
import com.example.whereismystuff.classes.ItemDataBaseAdapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

/**
 * This method checks all of the lost items in the database and finds corresponding matches based on the 
 * location and the name of the item
 * @author NullPointers
 *
 */
public class MergeView extends ListActivity {

	private ListView listView;

	ItemDataBaseAdapter mySQLiteAdapter;
	private int mYear;
	private int mMonth;
	private int mDay;
	static final int DATE_DIALOG_ID = 1;
	ArrayList<Item> currentItemList;
	String[] items;
	String s_Date;
	String tmpYear;
	
	private final String SLASH = "/";
	private final String EMPTY = "";
	
	ArrayList<String> tagsArray;
	
	AlertDialog.Builder tagDialog;
	String search, zipCode;

	
	/**
	 * Method used to Instantiate Object and set the Layout for the Activity
	 * @param Bundle
	 */
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mySQLiteAdapter = new ItemDataBaseAdapter(this);
		mySQLiteAdapter.open();
		Toast.makeText(getApplicationContext(), "wtf" + "", Toast.LENGTH_SHORT)
				.show();
		//Cursor cursor1 = mySQLiteAdapter.queueAllFiltered("NA", "FOUND", null);
		//Cursor cursor2 = mySQLiteAdapter.queueAllFiltered("NA", "LOST", null);
		Cursor cursor = mySQLiteAdapter.queueMatches();
				
		Toast.makeText(getApplicationContext(), cursor.getCount() + "",
				Toast.LENGTH_SHORT).show();
		startManagingCursor(cursor);
		NewListAdapter cursorAdapter = new NewListAdapter(this, cursor);
		setListAdapter(cursorAdapter);
		// mySQLiteAdapter.close();
	}



	/**
	 * When an item is clicked on the list, it calls the superclass 
	 */
	@Override
	protected void onListItemClick(ListView list, View view, int position,
			long id) {
		super.onListItemClick(list, view, position, id);
	}
	
	/**
	 * When the backbutton is pressed, it returns the user to the dashboard view
	 */
	public void onBackPressed() {
		try{
			Class c = Class.forName("com.example.whereismystuff.views.DashboardView");
			Intent i = getIntent();
			Bundle extras = i.getExtras();
			extras.putString("calling-activity", "all-items");
			//i.putExtra("calling-activity", "myitems");
			i = new Intent(getApplicationContext(), c);
			i.putExtras(extras);
			startActivity(i);
			finish();
		} catch (ClassNotFoundException e){
			e.printStackTrace();
		}
	}

}
